package com.realtyManage.springboot.Dao;


import com.realtyManage.springboot.Model.Do.Area;
import com.realtyManage.springboot.Model.Do.Dictionaries;
import com.realtyManage.springboot.Model.Vo.DictionariesEntity;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import javax.transaction.Transactional;
import java.util.List;

/**
 * 数据字典
 *
 * @author 杭州素色网络科技有限公司
 * @since 2019-09-23
 */

@Repository
public interface DictionariesRepository extends JpaRepository<Dictionaries, Integer>, JpaSpecificationExecutor<Dictionaries> {

    @Query(value="select * from dictionaries where is_show = 0",nativeQuery=true)
    List<Dictionaries> findDictionaries();

    @Query(value="select * from dictionaries where is_show = 0 and  type = ?1",nativeQuery=true)
    List<Dictionaries> findDictionariesType(String type);

    @Modifying
    @Query(value = "UPDATE dictionaries SET is_show = 1 WHERE menu_id = ?1",nativeQuery=true)
    int setIsShow(Integer menuId);

    @Modifying
    @Query(value = "UPDATE dictionaries SET is_show = 1 WHERE parent_id = ?1 or menu_id = ?1",nativeQuery=true)
    int setIsShows(Integer menuId);

    @Query(value="select * from dictionaries where is_show = 0 and  type = 'yhdj' and menu_id < ?1 ",nativeQuery=true)
    List<Dictionaries> findLevelUser(Integer level);

    @Query(value="select type,title from dictionaries where is_show = 0 and  menu_id = ?1 ",nativeQuery=true)
    String findType(String id);
}
